package csu.web.mypetstore;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@MapperScan("csu.web.mypetstore.mapper")
@EnableTransactionManagement
@SpringBootApplication
public class MyNewPetStoreApplication implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 匹配原路径结构
        String projectRoot = new ApplicationHome(getClass()).getDir().getParentFile().getParent();
        String imagePath = "file:" + projectRoot
                + "/src/main/resources/images/";

        registry.addResourceHandler("/images/**")
                .addResourceLocations(imagePath);
    }

    public static void main(String[] args) {
        SpringApplication.run(MyNewPetStoreApplication.class, args);
    }

}
